home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / 0utils.lha / 0Utils / WB_Delete.data < prev    next >
Text File  |  1995-08-30  |  5KB  |  216 lines

  1.  
  2. #ifdef TPLTER
  3.  
  4. WB_Delete = {
  5.  
  6.     SHORT = {{ simulate WB deleting a file }};
  7.  
  8.     BUGS = {{
  9.     * WB_Delete breaks on the first error
  10.     * Disk.info is not handled proberly
  11.     }};
  12.  
  13.     DESCRIPTION = {{
  14.     "WB_Delete file" deletes the files
  15.     "file" and "file.info" and additionally
  16.     deletes the DiskObject of "file" (the visible
  17.     icon) from the workbench.
  18.     }};
  19.  
  20.     TODO = {{
  21.     handling for "Disk.info" (we try to delete a file called 'disk')
  22.     }};
  23.  
  24.     HISTORY = {{
  25.     12-02-95 b_noll created
  26.     20-02-95 b_noll restructured source
  27.     21-02-95 b_noll added version/format-prefix/offset
  28.     20-03-95 b_noll added args diagnostics
  29.     19-08-95 b_noll created .data file
  30.     30-08-95 b_noll v1.3 added wildcard support,
  31.             added ctl-c handling (*ouch*)
  32.     }};
  33.  
  34.     Libraries = { Icon; };
  35.     Includes  = { "<string.h>" };
  36.  
  37.     Template = "FILE/M/A,ONLYICONS/S,ALL/S";
  38.     Arguments = {{
  39.     STRPTR* file;
  40.     ULONG    onlyIcons;
  41.     ULONG    all;
  42.     }};
  43.  
  44.     UserData = {{
  45.     UBYTE  apb[sizeof (struct AnchorPath) + 8 + MAXPATHLEN];
  46.     }};
  47.  
  48.     version = "1.3";
  49.     body = {{
  50.         long   cnt;         // for argv-slot
  51.         ULONG  error;        // for match rv
  52.         struct AnchorPath  *ap; // long aligned Anchor
  53.  
  54.         retval = RETURN_OK;
  55.  
  56.         ap              = (void *)(((ULONG)(userdata->apb) + 7) & ~7);
  57.  
  58.         ap->ap_Strlen     = MAXPATHLEN;
  59.         ap->ap_BreakBits  = 0;
  60.         ap->ap_FoundBreak = 0;
  61.  
  62.         for (cnt = 0; argv->file[cnt] && !retval && !IS_BROKEN(); ++cnt) {
  63.  
  64.         ap->ap_Flags = 0;
  65.  
  66.         for (error = MatchFirst(argv->file[cnt], ap); error == 0; error = MatchNext(ap)) {
  67.  
  68.             /* ---- this is a directory - have we set the ALL flag? */
  69.  
  70.             if (ap->ap_Info.fib_DirEntryType > 0 && argv->all) {
  71.  
  72.             /* ---- go into the other directory          */
  73.             /*    do not ye delete it - we'll come back */
  74.  
  75.             if (!(ap->ap_Flags & APF_DIDDIR)) {
  76.                 ap->ap_Flags |= APF_DODIR;
  77. //Printf (" entering %s\n", ap->ap_Buf);
  78.                 continue;
  79.             } /* if first visit */
  80.  
  81.             /* ---- leave the recent other directory */
  82.             /*    and delete it upon return */
  83.  
  84.             ap->ap_Flags &= ~APF_DIDDIR;
  85.  
  86.             } /* if isdir and 'all' */
  87.  
  88.             if (BREAKCHECK())
  89.             break;
  90. //Printf ("doing WC %s\n", ap->ap_Buf);
  91.             retval = do_delete (ap->ap_Buf, gvars);
  92.  
  93.         } /* for wilds */
  94.         MatchEnd(ap);
  95.  
  96.  
  97.         if (error != ERROR_NO_MORE_ENTRIES) { /* abnormal error */
  98.             if ((error == ERROR_OBJECT_NOT_FOUND) && !(ap->ap_Flags & APF_ITSWILD)) {
  99.  
  100.             /* ---- we leave this backdoor in order 2 B able 2 */
  101.             /*    delete icons whose files have been deleted */
  102.             /*    by just typing the filename (w/o .info)    */
  103.  
  104. //Printf ("doing NW %s\n", ap->ap_Buf);
  105.             retval = do_delete (argv->file[cnt], gvars);
  106.             if (retval)
  107.                 break;
  108.             } else {
  109.             retval = RETURN_ERROR;
  110.             break;
  111.             } /* if real error */
  112.         } /* if possible error */
  113.         } /* for all patterns */
  114.  
  115.  
  116.     }};
  117.  
  118.     addes = {{
  119.     static __inline ULONG do_delete (STRPTR path, struct _gvars *gvars) {
  120.         UBYTE buffer [MAXPATHLEN];
  121.         BPTR lock;
  122.         ULONG retval = 0;
  123.         ULONG len, isIcon = 0;
  124.  
  125.         strcpy (buffer, path);
  126.  
  127.         /* ---- ignore .info endings */
  128.         len = strlen(path);
  129.         if (len > 5 && (!stricmp(path + len - 5, ".info"))) {
  130.         len -= 5;
  131.         buffer[len] = 0;
  132.         isIcon = 1;
  133.         } /* if */
  134.  
  135.         Printf ("deleting %s\n", buffer);
  136.  
  137.         /* ---- Delete the main file */
  138.  
  139.         if (!argv->onlyIcons || isIcon)
  140.         if (lock = Lock(buffer, SHARED_LOCK)) {
  141.             UnLock(lock);
  142.  
  143.             if (!DeleteFile(buffer)) {
  144.             return RETURN_ERROR;
  145.             } /* if */
  146.         } /* if */
  147.  
  148.         /* ---- Delete the Icon and the .info file              */
  149.         /*        The rc may always be FALSE 'cause of FileNotFound */
  150.         /*        for this reason we just ignore it              */
  151.  
  152.         DeleteDiskObject(buffer);
  153.  
  154.         return retval;
  155.     } /* do_delete */
  156.  
  157.     }};
  158. };
  159.  
  160. #endif
  161.  
  162.     // for the sake of completeness, and i there is peraps an error
  163.     // in the new way ... this is the old version ...
  164.  
  165.     body = {{
  166.         long cnt;
  167.         UBYTE buffer [MAXPATHLEN];
  168.         BPTR lock;
  169.  
  170.         //if (IconBase = OpenLibrary(ICONNAME, 37)) {
  171.  
  172.         retval = RETURN_OK;
  173.  
  174.         for (cnt = 0; argv->file[cnt] && !retval; ++cnt) {
  175.  
  176.             buffer[0] = 0;
  177.             strcat (buffer, argv->file[cnt]);
  178.  
  179.             /* ---- Delete the main file */
  180.  
  181.             if (!argv->onlyIcons)
  182.             if (lock = Lock(buffer, SHARED_LOCK)) {
  183.             UnLock(lock);
  184.  
  185.             if (!DeleteFile(buffer)) {
  186.                 retval = RETURN_ERROR;
  187.                 break;
  188.             } /* if */
  189.             } /* if */
  190.  
  191.  
  192.             /* ---- Delete the Icon and the .info file */
  193.             /*        we delete file.info and diskobject separately, */
  194.             /*        'cause else we get probs w/ defdiskobjects */
  195.  
  196.             strcat (buffer, ".info");
  197.  
  198.             if (lock = Lock(buffer, SHARED_LOCK)) {
  199.             UnLock(lock);
  200.  
  201.             if (!DeleteFile(buffer)) {
  202.                 retval = RETURN_ERROR;
  203.                 break;
  204.             } /* if */
  205.             } /* if */
  206.  
  207.             /* ---- The rc is always FALSE 'cause of FileNotFound */
  208.             DeleteDiskObject(argv->file[cnt]);
  209.  
  210.         } /* for */
  211.  
  212.         //      CloseLibrary (IconBase);
  213.         //} /* if */
  214.     }};
  215.  
  216.